package com.risk.management.controller;

import com.risk.management.entity.Risk;
import com.risk.management.entity.User;
import com.risk.management.service.RiskService;
import com.risk.management.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/risk")
public class RiskAttachmentViewController {

    @Autowired
    private RiskService riskService;
    
    @Autowired
    private UserService userService;
    
    /**
     * 风险附件管理页面
     */
    @GetMapping("/{riskId}/attachments")
    public String attachmentsPage(@PathVariable Long riskId, Model model) {
        // 获取风险信息
        Risk risk = riskService.getRiskById(riskId);
        if (risk == null) {
            return "redirect:/project/list";
        }
        
        // 获取责任人信息
        User owner = null;
        if (risk.getOwnerId() != null) {
            owner = userService.getUserById(risk.getOwnerId());
        }
        
        model.addAttribute("risk", risk);
        model.addAttribute("owner", owner);
        
        return "risk/attachments";
    }
} 